package hos.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import javax.swing.WindowConstants;

import hos.po.P_information;

public class PatientManageView {
	public PatientManageView(JFrame main,P_information p1) {
		// TODO Auto-generated constructor stub
		JFrame jf = new JFrame("患者服务");
		jf.setVisible(true);
		jf.setSize(1000,800);
		jf.setLocationRelativeTo(main);
		jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		//登录后销毁登录界面
		main.dispose();
		//患者选项panel
		SpringLayout spLayout = new SpringLayout();
		JPanel managePanel = new JPanel(spLayout);
		JButton rigister = new JButton("挂号");
		JButton query = new JButton("信息查询");
		JButton pay = new JButton("缴费");
		JButton exit = new JButton("退出");
		JLabel welcome = new JLabel("欢迎用户:"+p1.getP_name());
		
		//各个组件的约束对象
		SpringLayout.Constraints rigisterCon = spLayout.getConstraints(rigister);
		SpringLayout.Constraints queryCon = spLayout.getConstraints(query);
		SpringLayout.Constraints payCon = spLayout.getConstraints(pay);
		SpringLayout.Constraints exitCon = spLayout.getConstraints(exit);
		SpringLayout.Constraints welcomeCon = spLayout.getConstraints(welcome);
		
		//welcome标签spring控制
		welcomeCon.setX(Spring.constant(0));
		welcomeCon.setY(Spring.constant(0));
		
		//功能标签控制：挂号，信息查询，缴费，退出
		rigisterCon.setHeight(Spring.constant(100));
		rigisterCon.setWidth(Spring.constant(150));
		rigisterCon.setX(Spring.constant(200));
		rigisterCon.setY(Spring.sum(welcomeCon.getConstraint(SpringLayout.SOUTH),Spring.constant(200)));
		
		queryCon.setHeight(Spring.constant(100));
		queryCon.setWidth(Spring.constant(150));
		queryCon.setX(Spring.sum(rigisterCon.getConstraint(SpringLayout.EAST), Spring.constant(50)));
		queryCon.setY(rigisterCon.getConstraint(SpringLayout.NORTH));
		
		payCon.setHeight(Spring.constant(100));
		payCon.setWidth(Spring.constant(150));
		payCon.setX(Spring.sum(queryCon.getConstraint(SpringLayout.EAST), Spring.constant(50)));
		payCon.setY(rigisterCon.getConstraint(SpringLayout.NORTH));
		
		exitCon.setHeight(Spring.constant(100));
		exitCon.setWidth(Spring.constant(150));
		exitCon.setX(queryCon.getConstraint(SpringLayout.WEST));
		exitCon.setY(Spring.sum(queryCon.getConstraint(SpringLayout.SOUTH), Spring.constant(200)));
		
		//组件添加到面板上
		managePanel.add(welcome);
		managePanel.add(rigister);
		managePanel.add(query);
		managePanel.add(pay);
		managePanel.add(exit);
		//退出按钮
		exit.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				jf.dispose();
			}
		});
		
		//挂号按钮
		rigister.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				PatientRigisterView patientRigister = new PatientRigisterView(main);
			}
		});
		
		jf.setContentPane(managePanel);
	}
	
}
